package fr.resasante.spring3.security;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jboss.logging.Logger;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * Authentification class
 * 
 * @author GEFFROY-DE-VILLEBLAN
 * 
 */
public class AuthenticationProcessingFilterImpl extends UsernamePasswordAuthenticationFilter {
	/**
	 * Logger for the class
	 */
	private static final Logger logger = Logger
			.getLogger(AuthenticationProcessingFilterImpl.class.getName());

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.web.authentication.
	 * AbstractAuthenticationProcessingFilter
	 * #successfulAuthentication(javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain,
	 * org.springframework.security.core.Authentication)
	 */
	@Override
	protected void successfulAuthentication(HttpServletRequest request,
			HttpServletResponse response, FilterChain chain, Authentication authResult)
			throws IOException, ServletException {
		super.successfulAuthentication(request, response, chain, authResult);
		final UserImpl userImpl = (UserImpl) authResult.getPrincipal();
		logger.info(userImpl.getUsername() + " is now authenticated");
	}
}
